<!DOCTYPE html>
<html>
<head>
<title>Physics Diagram - Rolling Disk</title>
<style>
  body {
    background-color: #f0f0f0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
  }
  canvas {
    background-color: #ffffff;
    border: 1px solid #ccc;
  }
</style>
</head>
<body>
<canvas id="physicsCanvas" width="450" height="500"></canvas>
<script>
  const canvas = document.getElementById('physicsCanvas');
  const ctx = canvas.getContext('2d');

  // Helper function to draw an arrow
  function drawArrow(fromx, fromy, tox, toy, color = 'black', lineWidth = 2) {
    const headlen = 10; // length of head in pixels
    const dx = tox - fromx;
    const dy = toy - fromy;
    const angle = Math.atan2(dy, dx);
    ctx.save();
    ctx.strokeStyle = color;
    ctx.fillStyle = color;
    ctx.lineWidth = lineWidth;
    ctx.beginPath();
    ctx.moveTo(fromx, fromy);
    ctx.lineTo(tox, toy);
    ctx.stroke();
    ctx.beginPath();
    ctx.moveTo(tox, toy);
    ctx.lineTo(tox - headlen * Math.cos(angle - Math.PI / 6), toy - headlen * Math.sin(angle - Math.PI / 6));
    ctx.lineTo(tox - headlen * Math.cos(angle + Math.PI / 6), toy - headlen * Math.sin(angle + Math.PI / 6));
    ctx.closePath();
    ctx.fill();
    ctx.restore();
  }

  // --- Parameters ---
  const R = 160;
  const r = 60;
  const O = { x: 190, y: 230 };
  const C = { x: O.x + R - r, y: O.y };
  const A = { x: C.x + r, y: C.y };

  // --- Drawing ---
  ctx.clearRect(0, 0, canvas.width, canvas.height);

  // Set default styles
  ctx.lineWidth = 2;
  ctx.strokeStyle = 'black';
  ctx.fillStyle = 'black';
  
  // Draw large circle (Ring)
  ctx.beginPath();
  ctx.arc(O.x, O.y, R, 0, 2 * Math.PI);
  ctx.stroke();

  // Draw small circle (Disk)
  ctx.beginPath();
  ctx.arc(C.x, C.y, r, 0, 2 * Math.PI);
  ctx.stroke();

  // --- Labels and Lines ---
  ctx.font = "italic 22px 'Times New Roman'";

  // O label
  ctx.fillText('O', O.x - 25, O.y + 5);
  
  // C label
  ctx.fillText('C', C.x - 8, C.y + 25);

  // A label
  ctx.fillText('A', A.x + 8, A.y + 5);

  // Dashed line for R
  ctx.save();
  ctx.setLineDash([5, 5]);
  ctx.lineWidth = 1.5;
  ctx.beginPath();
  ctx.moveTo(O.x, O.y);
  ctx.lineTo(O.x, O.y + 120);
  ctx.stroke();
  ctx.restore();
  ctx.fillText('R', O.x + 10, O.y + 70);

  // Dashed line for r and right angle symbol
  ctx.save();
  ctx.setLineDash([5, 5]);
  ctx.lineWidth = 1.5;
  ctx.beginPath();
  ctx.moveTo(C.x, C.y);
  ctx.lineTo(A.x, A.y);
  ctx.stroke();
  ctx.restore();
  ctx.fillText('r', C.x + r / 2 - 5, C.y - 10);

  // Right angle symbol at C
  ctx.save();
  ctx.lineWidth = 1;
  ctx.beginPath();
  const angleSize = 12;
  ctx.moveTo(C.x + angleSize, C.y);
  ctx.lineTo(C.x + angleSize, C.y - angleSize);
  ctx.lineTo(C.x, C.y - angleSize);
  ctx.stroke();
  ctx.restore();

  // --- Vectors ---
  const vec_len = 90;

  // Vector v_C
  drawArrow(C.x, C.y, C.x, C.y - vec_len);
  ctx.font = "italic 22px 'Times New Roman'";
  ctx.fillText('v', C.x + 12, C.y - vec_len / 2 + 8);
  ctx.font = "italic 16px 'Times New Roman'";
  ctx.fillText('C', C.x + 24, C.y - vec_len / 2 + 13);
  
  // Vector ω × r
  ctx.font = "italic 22px 'Times New Roman'";
  drawArrow(A.x, A.y, A.x, A.y + vec_len + 10);
  ctx.fillText('ω×r', A.x + 10, A.y + (vec_len + 10) / 2 + 8);

  // --- Caption ---
  ctx.font = "20px 'SimSun', '宋体'";
  ctx.textAlign = 'center';
  ctx.fillText('力图 1.15.1', canvas.width / 2, canvas.height - 30);

</script>
</body>
</html>